<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索 -->
    <el-card shadow="always">
      <el-row>
        <el-col :span="10">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="10"
          ><el-button type="primary" @click="goadd"
            >添加商品</el-button
          ></el-col
        >
      </el-row>

      <!-- 表格 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="goods_name" label="商品名称"> </el-table-column>
        <el-table-column prop="goods_price" label="商品价格"> </el-table-column>
        <el-table-column prop="goods_weight" label="商品重量">
        </el-table-column>
        <el-table-column prop="goods_time" label="创建时间"> 
          <template slot-scope="scope">
              {{scope.row.add_time | timmer }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row)"></el-button>
              <el-button type="primary" icon="el-icon-edit" circle></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 3, 5, 7]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { goodList ,delGoods} from "../../utils/api";
export default {
  data() {
    return {
      queryInfo: {
        query: "", //当前页数
        pagenum: 1, // 每页显示多少数据
        pagesize: 5,
      },
      total: 0,
      tableData: [],
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    // 获取商品列表数据
    async getlist() {
      var res = await goodList(this.queryInfo);
      console.log(8080,res);
      if (res.data.meta.status === 200) {
        this.$message.success(res.data.meta.msg);
        this.tableData = res.data.data.goods;
        this.total = res.data.total;
      }
    },

    // 删除
   async del(row){
      var res = await delGoods(row.goods_id)
      console.log("删除了",res);
      this.getlist()
    },
    // 分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.queryInfo.pagesize = val;
      this.getlist();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.queryInfo.pagenum = val;
      this.getlist();
    },

    goadd(){
     this.$router.push('/goods/add')
    }
  },
};
</script>
<style lang="scss">
.el-table {
  margin-top: 20px;
}
</style>